The data set contains information about three species of IRIS flowers namely:
Four features are collected from each sample, sepal-length, sepal-width, petal-length and petal-width in centi-meters.
# Common imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.express as px
iris_df = pd.read_csv("./data/IRIS.csv.gz", compression="gzip")
iris_df.sample(5)
| Unnamed: 0 | sepal_length | sepal_width | petal_length | petal_width | species | |
|---|---|---|---|---|---|---|
| 118 | 118 | 7.7 | 2.6 | 6.9 | 2.3 | Iris-virginica |
| 9 | 9 | 4.9 | 3.1 | 1.5 | 0.1 | Iris-setosa |
| 137 | 137 | 6.4 | 3.1 | 5.5 | 1.8 | Iris-virginica |
| 130 | 130 | 7.4 | 2.8 | 6.1 | 1.9 | Iris-virginica |
| 48 | 48 | 5.3 | 3.7 | 1.5 | 0.2 | Iris-setosa |
fig = px.scatter_3d(iris_df, x='sepal_length', y='sepal_width', z='petal_width',
color='species', template="plotly_dark")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
covid_df = pd.read_csv("./data/owid-covid-data.csv.gz", compression="gzip")
covid_df.sample(5)
| Unnamed: 0 | iso_code | continent | location | date | total_cases | new_cases | new_cases_smoothed | total_deaths | new_deaths | ... | female_smokers | male_smokers | handwashing_facilities | hospital_beds_per_thousand | life_expectancy | human_development_index | excess_mortality_cumulative_absolute | excess_mortality_cumulative | excess_mortality | excess_mortality_cumulative_per_million | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 143884 | 143884 | SWE | Europe | Sweden | 2020-07-02 | 69297.0 | 689.0 | 755.429 | 5411.0 | 41.0 | ... | 18.8 | 18.9 | NaN | 2.22 | 82.80 | 0.945 | NaN | NaN | NaN | NaN |
| 79806 | 79806 | KEN | Africa | Kenya | 2020-10-15 | 43143.0 | 602.0 | 423.571 | 805.0 | 8.0 | ... | 1.2 | 20.4 | 24.651 | 1.40 | 66.70 | 0.601 | NaN | NaN | NaN | NaN |
| 155992 | 155992 | ARE | Asia | United Arab Emirates | 2021-06-27 | 626936.0 | 2122.0 | 2129.571 | 1796.0 | 4.0 | ... | 1.2 | 37.4 | NaN | 1.20 | 77.97 | 0.890 | NaN | NaN | NaN | NaN |
| 112128 | 112128 | MKD | Europe | North Macedonia | 2020-09-10 | 15414.0 | 121.0 | 93.143 | 637.0 | 3.0 | ... | NaN | NaN | NaN | 4.28 | 75.80 | 0.774 | NaN | NaN | NaN | NaN |
| 58224 | 58224 | GHA | Africa | Ghana | 2020-04-04 | 205.0 | 0.0 | 9.143 | 5.0 | 0.0 | ... | 0.3 | 7.7 | 41.047 | 0.90 | 64.07 | 0.611 | NaN | NaN | NaN | NaN |
5 rows Ć 68 columns
required_columns = ["iso_code", "location", "continent", "date", "new_cases_smoothed", "total_cases"]
covid_df = covid_df.dropna(subset = required_columns)
covid_df = covid_df.sort_values("date")
covid_df[['iso_code', 'location']].sample(8)
| iso_code | location | |
|---|---|---|
| 82436 | KGZ | Kyrgyzstan |
| 57237 | GEO | Georgia |
| 65648 | HTI | Haiti |
| 134032 | SGP | Singapore |
| 125588 | SHN | Saint Helena |
| 146791 | TJK | Tajikistan |
| 103666 | MOZ | Mozambique |
| 130859 | SAU | Saudi Arabia |
covid_day_df = covid_df[covid_df.date == "2021-12-23"]
covid_day_df.sample(5)
| Unnamed: 0 | iso_code | continent | location | date | total_cases | new_cases | new_cases_smoothed | total_deaths | new_deaths | ... | female_smokers | male_smokers | handwashing_facilities | hospital_beds_per_thousand | life_expectancy | human_development_index | excess_mortality_cumulative_absolute | excess_mortality_cumulative | excess_mortality | excess_mortality_cumulative_per_million | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 104088 | 104088 | MOZ | Africa | Mozambique | 2021-12-23 | 167307.0 | 2445.0 | 1511.143 | 1961.0 | 1.0 | ... | 5.1 | 29.1 | 12.227 | 0.70 | 60.85 | 0.456 | NaN | NaN | NaN | NaN |
| 163127 | 163127 | WLF | Oceania | Wallis and Futuna | 2021-12-23 | 454.0 | 0.0 | 0.000 | 7.0 | 0.0 | ... | NaN | NaN | NaN | NaN | 79.94 | NaN | NaN | NaN | NaN | NaN |
| 73986 | 73986 | IRL | Europe | Ireland | 2021-12-23 | 680375.0 | 7411.0 | 5689.571 | 5890.0 | 0.0 | ... | 23.0 | 25.7 | NaN | 2.96 | 82.30 | 0.955 | NaN | NaN | NaN | NaN |
| 2158 | 2158 | ALB | Europe | Albania | 2021-12-23 | 206935.0 | 319.0 | 286.714 | 3181.0 | 1.0 | ... | 7.1 | 51.2 | NaN | 2.89 | 78.57 | 0.795 | NaN | NaN | NaN | NaN |
| 22653 | 22653 | VGB | North America | British Virgin Islands | 2021-12-23 | 3016.0 | 130.0 | 18.571 | 39.0 | 0.0 | ... | NaN | NaN | NaN | NaN | 79.07 | NaN | NaN | NaN | NaN | NaN |
5 rows Ć 68 columns
fig = px.scatter_geo(covid_day_df, locations="iso_code", color="continent",
hover_name="location", size="new_cases_smoothed",
projection="natural earth", template="plotly_dark")
fig.show()
fig = px.scatter_geo(covid_df, locations="iso_code", color="continent",
hover_name="location", size="total_cases",
projection="natural earth", animation_frame="date", template="plotly_dark")
fig.show()
import torchvision
import os
import matplotlib.pyplot as plt
from matplotlib import rc
from matplotlib.animation import FuncAnimation
from matplotlib import animation
rc('animation', html='jshtml')
frn = 10 # Number of frames to process in the animation
fps = 0.5 # Frames per second
mywriter = animation.PillowWriter(fps=fps)
mnist_dataset = torchvision.datasets.MNIST(root = "data/mnist", train = True, download = True, transform=torchvision.transforms.ToTensor())
fig, ax = plt.subplots(figsize = (10, 10))
def change_plot(frame_idx):
ax.cla()
image_tensor = mnist_dataset[frame_idx][0]
image_tensor_gray = image_tensor[0]
image_tensor_gray = image_tensor_gray * 255
ax.matshow(image_tensor_gray, cmap = "gray")
for i in range(image_tensor_gray.shape[0]):
for j in range(image_tensor_gray.shape[1]):
ax.text(i, j, str(int(image_tensor_gray[j][i].item())), va = "center", ha = "center", color = "blue", fontsize = "small")
ax.axis("off")
plt.tight_layout()
anim = FuncAnimation(fig, change_plot, frn, interval=1000 / fps)
plt.close()
anim
<Figure size 432x288 with 0 Axes>
mywriter = animation.PillowWriter(fps=fps)
if not os.path.exists("./assets/gif"):
os.makedir("./assets/gif")
anim.save('./assets/gif/mnist.gif',writer=mywriter)
<Figure size 432x288 with 0 Axes>